package com.xnfh.field.ui.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.xnfh.common.bean.Record
import com.xnfh.field.R
import com.xnfh.field.databinding.ItemFieldListLayoutBinding
import com.xnfh.image.ImageHelper
import com.xnfh.image.ImageUrl

/**
 * @Description:
 * @Author: ziheng
 * @CreateDate: 2023/11/28 15:26
 * @UpdateUser: ziheng
 * @UpdateDate: 2023/11/28 15:26
 * @UpdateRemark: 更新说明
 */
class FieldListAdapter: BaseQuickAdapter<Record, BaseDataBindingHolder<ItemFieldListLayoutBinding>>(R.layout.item_field_list_layout) {
    companion object{
        var currSelect = -1
    }
    override fun convert(holder: BaseDataBindingHolder<ItemFieldListLayoutBinding>, item: Record) {
        ImageHelper.instance?.loadNetImg(context,ImageUrl.BASEURL+item.realPath,holder.dataBinding?.itemFieldListPic,
            com.xnfh.common.R.mipmap.image_error, com.xnfh.common.R.mipmap.image_error)
        holder.setText(R.id.item_field_list_name,item.fieldName)
        holder.setText(R.id.item_field_address,item.address)
        holder.setText(R.id.item_field_pz_and_mu,"${item.plantCropName}  |  ${item.areaMu}${context.getString(R.string.field_detail_mu)}")
        if(item.isSelect){
            holder.dataBinding?.fieldListCon?.background = context.resources.getDrawable(com.xnfh.common.R.drawable.shape_bg_fff_bk_00c258_8_readiu)
        }else{
            holder.dataBinding?.fieldListCon?.background = context.resources.getDrawable(com.xnfh.common.R.drawable.shape_fff_8_readiu)
        }
    }
    fun setOnSelectItem(position: Int){
        if(currSelect != -1){
            getItem(currSelect).isSelect = false
            notifyItemChanged(currSelect)
        }
        currSelect = position
        getItem(currSelect).isSelect = true
        notifyItemChanged(currSelect)
    }
}